-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] 'Query' support for channels.list.joined, groups.list, groups.listAll, im.list #9424
Conversation
…groups.listAll, im.list Signed-off-by: Eugene Bolshakov <pub@relvarsoft.com>
Signed-off-by: Eugene Bolshakov <pub@relvarsoft.com>
It looks interesting, @graywolf336 what do you think? |
Signed-off-by: Eugene Bolshakov <pub@relvarsoft.com>
The last change allows to add customFields for IM (Direct Messages). The previously changed im.list now allows to search using 'query' like { "customFields.field1": { "$regex": "^org"}} as shown below:
Need to note that:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. If you don't mind, when this gets merged, can you submit a pull request to our Documentation repo to update the docs for these methods?
@xbolshe what happens when the value of the user's custom fields change? |
@graywolf336 Sure. I can update Documentation repo with changes of this PR and usage examples. |
Signed-off-by: Eugene Bolshakov <pub@relvarsoft.com>
@graywolf336 Docs PR is added (see a link above). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@graywolf336 @rodrigok do we want to open this up to any query? Or should this be limited in some way?
'u._id': this.userId | ||
}); | ||
|
||
let rooms = _.pluck(RocketChat.models.Subscriptions.find(ourQuery).fetch(), '_room'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to just blindly pass query through?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geekgonecrazy it's not exactly passing the query blindly. The function parseJsonQuery
handles several cases and line 410 ensures that the calling user is only able to query their own...although I say that without trying it. @xbolshe what happens whenever someone passes the query with a nested property like the one the string u._id
is doing? For example, { "u": { "_id": "other_users_id" } }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@graywolf336 One string and nested string will have different actions as described here: https://stackoverflow.com/questions/16002659/how-to-query-nested-objects
Becase "u" has several fields inside, only nested "_id" will find no records at all:
But one string provides a records selection:
So, need to use all fields nested inside "u" like shown below:
Providing 2 different values for one field like "u._id" will cause a search of no records:
Answering on your question, one field cannot be equal at the same time to 2 different values.
If a value will be duplicated like shown below, a search will be performed:
So, only records belongs to this.userId will be searched for channels.list.joined.
I have tried to inherit constraints like this.userId applied before my changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into it in more depth! 👍
@RocketChat/core
Closes #9423
New in the database: customFields is added to Subscription to get it from RocketChat.models.Subscriptions.find(ourQuery).fetch().
Example after this fix : get all joined channels with customFields.field1 = "aaa-2"